﻿using System;
using System.Collections.Generic;
using SaxParser;

namespace SaxParserCA
{
    class Program
    {
        #region Constructors

        static Program()
        {
            parser.OnElementStart += new MySaxParser.ElenemtStartEventHandler(WriteNewElement);
            parser.OnElementEnd += new MySaxParser.ElenemtEndEventHandler(WriteSomeText);
            parser.OnText += new MySaxParser.TextEventHandler(WriteSomeText);
            parser.OnComment += new MySaxParser.CommentEventHandler(WriteSomeText);
            parser.OnDocumentDeclaration += new MySaxParser.DocumentDeclarationEventHandler(WriteSomeText);
            parser.OnError += new MySaxParser.ErrorEventHandler(WriteSomeText);
        }

        #endregion

        static void Main(string[] args)
        {
            parser.Parse(path);
            Console.ReadKey();
        }

        #region Calling Functions

        private static void WriteNewElement(object sender, ElementStartEventArgs args)
        {
            Console.WriteLine("New tag. Name: {0}", args.TagName);
            foreach (KeyValuePair<string, string> atr in args.Attributes)
            {
                Console.WriteLine("Atribute name: {0}; value: {1}", atr.Key, atr.Value);
            }
        }

        private static void WriteSomeText(object sender, MyEventArgs args)
        {
            Console.WriteLine("{0} {1}", args.Action, args.Text);
        }


        #endregion

        #region Fields

        private static string path = "exmpl.xml";
        private static MySaxParser parser = new MySaxParser();

        #endregion
    }
}
